/**
 *
 * Escola
 * 04/06/2012 - 13:41:12
 *
 */
package escola.spring;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StringUtils;

/**
 * @author Jonathan
 *
 */
public class ConfigurationSpring {
	
	private static DefaultListableBeanFactory beanFactory;

	public static void setupFactory() {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getConfigFiles());
		beanFactory = (DefaultListableBeanFactory) context.getBeanFactory();
	}

	private static String[] getConfigFiles() {
		List<String> files = new ArrayList<String>();
		files.add("/escola/spring/*.xml");
		files.add("/escola/dao/spring-dao.xml");
		files.add("/escola/logic/spring-logic.xml");
		return StringUtils.toStringArray(files);
	}
	
	public static Object getBean(String beanName) {
		return beanFactory.getBean(beanName);
	}

}
